package com.xueqiu.lovepetmedicalmanagersystem.controller;

import com.xueqiu.lovepetmedicalmanagersystem.pojo.Employee;
import com.xueqiu.lovepetmedicalmanagersystem.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author xueqiu
 */
@Controller
@RequestMapping("/employee")
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    /**
     * 跳转控制器；跳转到新增页面
     * @return 新增页面URL
     */
    @RequestMapping("/toAdd")
    public String toAddEmployee() {
        return "employee/add";
    }

    /**
     * 员工新增
     * @param employee 数据源
     * @param model 模型参数
     * @return 新增成功跳转到登陆页面；新增失败跳转到员工新增页面
     */
    @RequestMapping("/Add")
    public String employeeAdd(Employee employee, Model model) {
        System.out.println(employee.toString());
        Integer i = employeeService.insertEmployee(employee);
        if (i > 0) {
            System.out.println("==============================================>");
            model.addAttribute("msg", "添加成功，请登录！！");
            return "login";
        } else {
            System.out.println("==============================================<");
            model.addAttribute("msg", "添加失败！！！");
            return "employee/add";
        }

    }
}
